package rsb21411ls.d1117;


import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Demo03 {
    public static void main(String[] args) {


        List<Demo02.Person> list =new ArrayList<>();
        list.add(new Demo02.Person("poi","m"));
        list.add(new Demo02.Person("poi","m"));
        list.add(new Demo02.Person("poi","k"));
        list.add(new Demo02.Person("poi","d"));
        list.add(new Demo02.Person("poi","e"));
        System.out.println(list);
        //集合的遍历
        for (Demo02.Person per :list){
            System.out.println(per);
        }
        //lambda 的foreach
        list.forEach(obj->{ System.out.print(obj+"----");});
        //迭代器
        //创建 迭代器对象
        System.out.println("[");
        Iterator<Demo02.Person> it =list.iterator();
        while (it.hasNext()){
            Demo02.Person p= it.next();//指针移动
            if (!p.getCountry().equals("m"));{
                //p.setCountry("k");}
                it.remove();
                //p.remove();
            }


            System.out.print( p.getName()+"------");
        }
        System.out.println("]");
        //传统for   删除
       /* for (int i=0; i<list.size();i++){
            Demo02.Person p=list.get(i);
            if (!p.getCountry().equals("m")){
                list.remove(i);
            }
        }*/

        System.out.println(list);

    }
}

